package com.shanghaiyimu.yimiyangche.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.adapter.GaiZhuangLVAdapter;
import com.shanghaiyimu.yimiyangche.bean.GoodsBean;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class MyFragment1 extends Fragment {
    private String mText;
    private TextView textView;
    private ListView listView;
    private GaiZhuangLVAdapter adapter;
    private List<GoodsBean> list ;

    public MyFragment1() {
        // Required empty public constructor
    }
    /**
     * 静态工厂方法需要一个int型的值来初始化fragment的参数，
     * 然后返回新的fragment到调用者
     */
//    public static MyFragment1 newInstance(String name) {
//        MyFragment1 f = new MyFragment1();
//        Bundle args = new Bundle();
//        args.putString("name", name);
//        f.setArguments(args);
//        return f;
//    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        Bundle bundle = getArguments();
//        if (bundle != null) {
//            mText= bundle.get("name").toString();
//        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_my_fragment1, container, false);
        initData();
        initView(view);
        return view;
    }

    private void initData() {
        list = new ArrayList<>();
        for (int i = 0; i < 16; i++) {
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setContent("丰途/RAYS G25 18 寸锻造轮毂 孔距 5*112 奥迪A6 前轮");
            goodsBean.setName("553"+i+"0.00");
            list.add(goodsBean);
        }
//        adapter.notifyDataSetChanged();

    }

    private void initView(View view) {
//        textView = (TextView) view.findViewById(R.id.txt_frg);
//        textView.setText(mText);
        listView = (ListView) view.findViewById(R.id.gaizhuang_lv);
        adapter = new GaiZhuangLVAdapter(getContext(),list);
        listView.setAdapter(adapter);
    }

}
